﻿using System;
using System.Windows.Forms;
using Wise.TimeWarrior.DTO;
using Wise.TimeWarrior.Forms.Interfaces;

namespace Wise.TimeWarrior.Forms
{

    /// <summary>
    /// <see cref="IConfigurationForm"/>
    /// </summary>
    public partial class ConfigurationForm : Form, IConfigurationForm
    {
        /// <summary>
        /// .ctor
        /// </summary>
        public ConfigurationForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// <see cref="Form.OnShown"/>
        /// </summary>
        protected override void OnShown(EventArgs e)
        {
            propGrid.SelectedObject = ConfigurationDto;
            base.OnShown(e);
        }
        /// <summary>
        /// <see cref="Form.OnFormClosing"/>
        /// </summary>
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                Visible = false;
            }
            else
            {
                base.OnFormClosing(e);
            }
        }
        /// <summary>
        /// <see cref="IConfigurationForm.SaveSettingsEvent"/>
        /// </summary>
        public event EventHandler SaveSettingsEvent;
        /// <summary>
        /// <see cref="IConfigurationForm.ConfigurationDto"/>
        /// </summary>
        public ConfigurationDto ConfigurationDto { get; set; }

        /// <summary>
        /// action executed after click save button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            SaveSettingsEvent(sender,e);
        }
    }
}
